/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.stockkeeper;

import java.awt.Component;
import java.awt.Dialog;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.letmeshare.stockkeeper.view.dashboard.Dashboard;
import org.letmeshare.stockkeeper.view.login.LoginActionListerner;
import org.letmeshare.stockkeeper.view.login.LoginEvent;
import org.letmeshare.stockkeeper.view.login.Loginview;

/**
 *
 * @author abin
 */
public class AppController {

    boolean login = false;Loginview loginview;

    public AppController() {
        init();
    }

    public void init() {
        try {
            if (!login) {
                loginview = new Loginview();
                loginview.addLoginActionListener(new LoginActionListerner() {
                    public void onLoginAction(LoginEvent le) {
                        System.out.println(le.getUserName() + String.copyValueOf(le.getPassword()));
                        login = true;
                        ((Component) le.target).setVisible(false);
                        init();
                    }
                });
            } else {
                Dashboard dashboard = new Dashboard();
                
            }
        } catch (Exception e) {
            
           JOptionPane.showMessageDialog(loginview, "An Error occured during App initialization" +e.getMessage(), "Application Error", JOptionPane.ERROR_MESSAGE);
        }

    }
}
